package _01线程等待和唤醒;

public class DemoNotify {
    public static void main(String[] args) {
        Object o = new Object();

//        try {
//            System.out.println("main线程开始");
//            synchronized (o){
//                o.wait();
//            }
//            System.out.println("main线程结束");
//
//        }catch (InterruptedException e) {
//            e.printStackTrace();
//        }



        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("线程一开始");
                    synchronized (o){
                        o.wait();
                    }
                    System.out.println("线程一结束");

                }catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {

                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("线程三开始");
                    synchronized (o){
                        o.wait();
                    }
                    System.out.println("线程三结束");

                }catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {

                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("线程二开始");
                    synchronized (o){
                        Thread.sleep(3000);
                        o.notify();
                    }
                    System.out.println("线程二唤醒成功");

                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {

                }
            }
        }).start();
    }
}
